#include "EventEntry.hpp"
#include "EventResource.hpp"

#include <gtkmm/gestureclick.h>
#include <gtkmm/label.h>
#include <sigc++/signal.h>
#include <iostream>
/*
void
Event::EventEntry::class_init(void *g_class, void *)
{
    g_return_if_fail(g_class != NULL);
    auto klass = static_cast<GtkWidgetClass *>(g_class);
    gtk_widget_class_set_css_name(klass, "event-entry");
}
*/
Event::EventEntry::EventEntry()
    : Glib::ObjectBase("EventEntry")
{
    this->can_modify = false;
    std::cout << "Register Event::EventEntry in GType System.\n";
} 

Event::EventEntry::EventEntry(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refBuilder)
    : Glib::ObjectBase("EventEntry")
    , Gtk::Box(cobject), m_refBuilder(refBuilder)
{
    this->can_modify = false;
    //gtk_widget_remove_css_class(GTK_WIDGET(this->gobj()), "entry");
}

Event::EventEntry *
Event::EventEntry::create()
{
    auto refBuilder = get_resource_from("/org/korack/event/ui/EventEntry.xml");
    auto event_entry = Gtk::Builder::get_widget_derived<Event::EventEntry>(refBuilder, "event_entry");
    if (!event_entry)
    {
        throw std::runtime_error("No object id=event_entry in ui file.");
    }
    return event_entry;
}

void
Event::EventEntry::set_can_modify(bool can_modify)
{
    if (this->can_modify == can_modify)
        return;
    if (can_modify)
        this->add_css_class("entry");
    else
        this->remove_css_class("entry");
    this->can_modify = can_modify;
}

Glib::SignalProxy<void(int, double, double)>
Event::EventEntry::signal_clicked()
{
    /* Brain teasers */
    auto gestureClicked = Gtk::GestureClick::create();
    gestureClicked->set_button(GDK_BUTTON_PRIMARY);
    add_controller(gestureClicked);
    return gestureClicked->signal_released();
}

void Event::EventEntry::set_event_name(const Glib::ustring &name)
{
    auto event_name = m_refBuilder->get_widget<Gtk::Label>("event_name");
    event_name->set_label(name);
}

void Event::EventEntry::set_event_describe(const Glib::ustring &describe)
{
    auto event_describe = m_refBuilder->get_widget<Gtk::Label>("event_describe");
    event_describe->set_label(describe);
}

void Event::EventEntry::set_event_end_time(const Glib::ustring &end_time)
{
    auto event_end_time = m_refBuilder->get_widget<Gtk::Label>("event_end_time");
    event_end_time->set_label(end_time);
}

void Event::EventEntry::set_group_name(const Glib::ustring &name)
{
    auto group_name = m_refBuilder->get_widget<Gtk::Label>("group_name");
    group_name->set_label(name);
}

